<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp" %>

<!DOCTYPE html>
<html>
<head>
    <title><spring:message code="message.basic"/></title>
    <%@ include file="/WEB-INF/component/commonCSS.jsp" %>
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
							
    <section class="content-header">
        <h1><spring:message code="message.basic"/></h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i>首页</a></li>
            <li class="active"><a href="#"><spring:message code="message.basic"/></a></li>
        </ol>
    </section>
    
    <section class="content">
        <div class=" box box-success">
            <div class="box-body">
                <div class="form-inline">
                    <div class="form-group form-group-xs">
                        <label for="name">用户名称:</label>
                        <input class="form-control" type="text" id="name" placeholder="用户名称" maxlength="50" />
                    </div>
                    <button type="button" class="btn btn-success btn-sm" onclick="search();">查&nbsp;询</button>
                </div>
            </div>
        </div>
        
        <table class="jqgrid" id="gridlist"></table>
        <div id="gridpage"></div>
        
        <div class=" box box-warning bottongroup">
        </div>
        
        <div class="modal fade" id="dialog" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header bg-primary">
						<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
						<h5 class="modal-title">用户管理新增</h5>
					</div>
					<div class="modal-body">
						<div class="form-group form-group-xs">
							<label for="userType" class="control-label">用户类型:</label>
							<select id="userType" class="form-control">
								<option value="">请选择</option>
								<c:if test="${ userTypeList != null }">
									<c:forEach items="${ userTypeList }" var="userType">
										<option value="${userType.key}">${userType.value}</option>
									</c:forEach>
								</c:if>
							</select>
						</div>
						
					</div>
					<div class="modal-footer">
						<button type="button" class="btn btn-primary btn-sm" onclick="ok();">确&nbsp;认</button>
						<button type="button" class="btn btn-danger btn-sm" id="close" data-dismiss="modal">关&nbsp;闭</button>
					</div>
				</div>
			</div>
		</div>
  
    </section>
    
    <%@ include file="/WEB-INF/component/commonJS.jsp" %>
    
    <script type="text/javascript">
    	function selectUserType() {
    		$('#dialog').modal({
                keyboard: true
            });
    	}
    	
    	function ok() {
    		var userType = $("#userType").val();
    		if (userType != null && userType != "") {
    			document.location = "${ctx}/sysUser/zxUserSelected.html?userType=" + userType;
    		} else {
    			$.HN.message.alert("请选择用户类型！", "消息", "warn");
    		}
    	}
    
    	function changeStatus(id, status) {
    		$.post("changeStatus.html", {
    			id : id,
    			status : status
    		}, function(result) {
    			if (result.success) {
    				var curpage = $("#gridlist").jqGrid('getGridParam', 'page');
    				search(curpage);
    				$.HN.message.alert("操作成功！", "消息", "success");
    			} else {
    				$.HN.message.alert("操作失败！", "消息", "error");
    			}
    		}, "json").error(function(err) {
    			top.window.document.location = "${ctx}/login.html"; 
    		});
    	}
    	
    	function batchChangeStatus(status) {
    		var rowIds = $("#gridlist").jqGrid("getGridParam", "selarrrow") || [];
    		if (rowIds.length <= 0) {
    			$.HN.message.alert("请选择要操作的行！", "消息", "error");
    			return;
    		}
    		var list = [];
    		for (var i=0; i<rowIds.length; i++) {
    			rowId = rowIds[i];
    			list.push({"id":rowId, "status":status});
    		}
    		$.post("batchChangeStatus.html", {
    			"array" : json.jsonToString(list)
    		}, function(result) {
    			if (result.success) {
    				var curpage = $("#gridlist").jqGrid('getGridParam', 'page');
    				search(curpage);
    				$.HN.message.alert("操作成功！", "消息", "success");
    			} else {
    				$.HN.message.alert("操作失败！", "消息", "error");
    			}
    		}, "json").error(function(err) {
    			top.window.document.location = "${ctx}/login.html"; 
    		});
    	}
    	
    	function search(page) {
    		var name = $.trim($("#name").val());
    		$("#gridlist").jqGrid('setGridParam',{  
    	        datatype:'json',
    	        postData:{"name":name},
    	        page : (page || 1)
    	    }).trigger("reloadGrid"); //重新载入  
    	}
    
        $(function () {
            $("#gridlist").jqGrid({
                url: "getZxUserList.html",
                mtype: "post",
                datatype: "json",
                autowidth: true,
                height: 270,
                colNames: [  '帐号',	'用户名称', '用户类型', '邮箱','状态', '备注', '操作' ],
                colModel: [
					{ name: 'username', width: 8, align:"center", sortable: false},
                    { name: 'name', width: 10, align:"left", sortable: false},
                    { name: 'typeName', width: 5, align:"center", sortable: false },
                    { name: 'email', width: 10, align: "left", sortable: false},
                    { name: 'statusName', width: 5, align: "center", sortable: false},
                    { name: 'remark', width: 10, align:"left", sortable: false},
                    { name: 'operate', width: 10, align:"center", sortable: false,
                    	formatter : function(val, opts, rowdata) {
	                    	var str =  "<a href='PassWordUpdate.html?opType=1&id=" + rowdata.id + "&userType=" + rowdata.type + "'>编辑</a>";
	               			/* if(rowdata.status == 0){
	               				str += "<a href='javascript:changeStatus(\""+rowdata.id+"\", 1);'>启用</a>"
	               			}else{
	               				str += "<a href='javascript:changeStatus(\""+rowdata.id+"\", 0);'>停用</a>"
	               			} */
	                    	return str;
                    }}
                ],
                rowNum: 10,
                rowList: [10, 20, 30],
                rownumbers: true,
                pager: "#gridpage",
                multiselect: true, 
                viewrecords: true,
                caption: "基本信息",
                jsonReader: {
                    id: "id"
                }
            });
            
            $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
            
            $(window).trigger("resize");
            
        });
    </script>
</body>
</html>












